#include<iostream>
#include<pthread.h>
#include<string>
#include<unistd.h>

__thread int count = 1;

std::string addr(int &c)
{
    char Addr[64];
    snprintf(Addr, sizeof(Addr), "%p", &c);
    return Addr;
}

void* routine1(void* args)
{
    while(1)
    {
        std::cout<<"thread -1, count = " << count <<"           "  << addr(count)<<std::endl;
        count++;
        sleep(1);
    }   

}

void* routine2(void* args)
{
    while(1)
    {
        std::cout<<"thread -2, count = " << count <<"           "  << addr(count)<<std::endl;
        count++;
        sleep(1);
    }

}

int main()
{
    pthread_t tid1, tid2;
    pthread_create(&tid1, nullptr, routine1, nullptr);
    pthread_create(&tid2, nullptr, routine2, nullptr);

    pthread_join(tid1, nullptr);
    pthread_join(tid2, nullptr );

    return 0;
}